//
//  ForGetPWNextViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/10/17.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "ForGetPWNextViewController.h"
#import "RegisterVIew.h"
#import "JTCSM.h"

#define KTop 10
#define KWidthOfRegister 40

@interface ForGetPWNextViewController ()<UITextFieldDelegate,UIAlertViewDelegate>
{
    NSArray *imageNameArray;
    NSArray *placeholderArray;
    NSString *passWord ;
    NSString *passWord1 ;
    NSMutableArray* _areaArray;
    RegisterVIew * registerV;
    UIButton *getKeyBtn;
    NSTimer* _timer1;
    NSTimer* _timer2;
    NSInteger count ;
    UIButton *radioBtn;
    BOOL isSelector;
    NSMutableArray *textFieldArray;
    int idx ;
    
}


@end

@implementation ForGetPWNextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =[UIColor whiteColor];
    self.navigationController.navigationBar.hidden = NO;
    textFieldArray = [NSMutableArray arrayWithCapacity:2];
    //设置barbuttonitem
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    //回收键盘
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeKeyBoard)];
    [self.view addGestureRecognizer:tap];
    [self aboutDataArray];
    [self layoutView];
    
    // Do any additional setup after loading the view.
}
- (void)gotBack{
    
//    self.navigationController.navigationBar.hidden = YES;
    
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)layoutView{
    
    UIView *backView = [[UIView alloc]init];
    backView.userInteractionEnabled = YES;
    [self.view addSubview:backView];
    idx = 0;
    placeholderArray=@[@"输入新密码",@"确认新密码"];
    for (int i = 0; i < placeholderArray.count; i++) {
        registerV = [[RegisterVIew alloc]initWithFrame:CGRectMake(-20,10+i*60, self.view.frame.size.width, KWidthOfRegister+20) labeTtext:nil placeholder:placeholderArray[i]];
        registerV.userInteractionEnabled =YES;
        registerV.textField.delegate = self;
        registerV.textField.tag = 100+i;
        [registerV.textField setValue:RGBACOLOR(120, 130, 140,1) forKeyPath:@"_placeholderLabel.textColor"];
        registerV.label.textAlignment = NSTextAlignmentLeft;
        [backView addSubview:registerV];
        [textFieldArray addObject:registerV];
        [self addImageWith:registerV];
        [self addLineWith:registerV];
        registerV.textField.secureTextEntry = YES;
        if (i == 1) {
            backView.frame = CGRectMake(0, KagainChangeHeight, self.view.frame.size.width, registerV.frame.origin.y + registerV.frame.size.height);
        }
        
    }
    UIButton *doneBtn = [UIButton initWithFrame:CGRectMake(20, KVIEW_Y(backView)+80 , KCONTROLLERWith-40, 40) backgrandColor:RGBACOLOR(227, 72, 40, 1) titleColor:[UIColor whiteColor] title:@"提   交" titleFont:14];
    [doneBtn addTarget:self action:@selector(goToCompleteVC) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:doneBtn];
    [df layerWithView:doneBtn radius:5 width:0 color:nil];
    
}

- (void)goToCompleteVC{
    [self.view endEditing:YES];
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:2];
    LoadData *request = [[LoadData alloc]init];
    [dict setObject:self.phoneNumber==nil?@"":self.phoneNumber forKey:@"mobile"];
    [dict setObject:self.code==nil?@"":self.code forKey:@"code"];
    [dict setObject:passWord==nil?@"":passWord forKey:@"password"];
    [dict setObject:passWord1==nil?@"":passWord1 forKey:@"password2"];

    NSLog(@"%@",dict);
    
    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"PassPort/findPass") withDict:dict superView:self.view isAddtag:NO  Block:^(id result) {
        
        
        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
        if ([isreturn isEqualToString:@"1"]) {
            
            [df showAlertWithTitle:@"修改成功" message:@"请重新登录" btn1:@"确定" btn2:nil btn3:nil delegate:self tag:12];

            
        }else{
            [df showAlertWithTitle:[result objectForKey:@"msg"] message:nil btn1:@"返回" btn2:nil btn3:nil delegate:nil tag:0];
            //            [self theRequestOftuwenyanzhengma];
        }
        
    }];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag == KAlertVTag+12) {
        [self.navigationController popToRootViewControllerAnimated:YES];

    }
}

#pragma mark --添加灰线条
-(void)addImageWith:(UIView *)fatherview{
    
    UILabel *lable =[[UILabel alloc] initWithFrame:CGRectMake(20,  fatherview.frame.size.height-59, 77, 60)];
    [lable setText:imageNameArray[idx++]];
    lable.textAlignment=YES;
    lable.backgroundColor =[UIColor whiteColor];
    //imageView.image=[UIImage imageNamed:imageNameArray[idx++]];
    lable.font =[UIFont fontWithName:@"Arial" size:15.0];
    UIView *view1 =[[UIView alloc] initWithFrame:CGRectMake(99, 20, 1.5, 20)];
    view1.backgroundColor =[UIColor colorWithRed:226/255.0 green:227/255.0 blue:228/255.0 alpha:1];
    [fatherview addSubview:view1];
    [fatherview addSubview:lable];
    
    
}
- (void)addLineWith:(UIView *)fatherview{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, fatherview.frame.size.height-1, KCONTROLLERWith, 1.5)];
    view.backgroundColor = RGBACOLOR(226, 227, 228,1);
    [fatherview addSubview:view];
    
}

- (void)getKeyboardPodWithTextfield:(UITextField *)textfield{
    if (textfield.tag == 100 || textfield.tag == 101 ) {
        textfield.secureTextEntry = YES;
    }
    //    if (textfield.tag == 101||textfield.tag == 102) {
    //        textfield.secureTextEntry = YES;
    //    }
    
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    if (textField.tag == 100) {
        passWord = textField.text;
    }
    if (textField.tag == 101) {
        passWord1 = textField.text;
    }
    //    if (textField.tag == 101) {
    //        passWord = textField.text;
    //    }
    //    if (textField.tag == 102) {
    //        passWord1 = textField.text;
    //    }
    
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder] ;
    return YES;
}
- (void)removeKeyBoard{
    [self.view endEditing:YES];
}
- (void)aboutDataArray{
    
    imageNameArray =@[@"新密码",@"确认密码"];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
